<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation()
    {
        parent::CI_Form_validation();
    }

	function check_phone($str)
	{
		if(!empty($str))
		{
			$bool = ( ! preg_match("/^\+?[0-9|\.| |-]{6,20}$/", $str)) ? FALSE : TRUE;
			if (!$bool)
				$this->set_message('check_phone', 'The %s field must contain a valid phone number.');
		}	
		else
			$bool = TRUE;
		
		return $bool;
	}
	
	function valid_email($str)
	{
		if(!empty($str))
		{
			$bool = ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
			if (!$bool)
				$this->set_message('valid_email', 'The %s field must contain a valid email address.');
		}	
		else
			$bool = TRUE;
		
		return $bool;	
	}

	
}

